"""
需求模型
"""

from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey, JSON
from sqlalchemy.sql import func
from sqlalchemy.orm import relationship
from ..core.database import Base


class Requirement(Base):
    """需求模型"""
    __tablename__ = "requirements"

    id = Column(Integer, primary_key=True, index=True)
    title = Column(String(200), nullable=False, index=True)
    description = Column(Text)
    content = Column(Text)
    tags = Column(JSON)  # 存储标签数组
    status = Column(String(20), default="active", index=True)  # active, archived, deleted
    priority = Column(Integer, default=1)  # 1-5优先级
    
    # 外键
    creator_id = Column(Integer, ForeignKey("users.id"))
    
    # 时间戳
    created_at = Column(DateTime(timezone=True), server_default=func.now())
    updated_at = Column(DateTime(timezone=True), onupdate=func.now())
    
    # 关系
    creator = relationship("User", back_populates="requirements")
    test_cases = relationship("TestCase", back_populates="requirement", cascade="all, delete-orphan")
    analysis_records = relationship("AnalysisRecord", back_populates="requirement")
    ui_automation_scripts = relationship("UiAutomationScript", back_populates="requirement", cascade="all, delete-orphan") 